/*******************************************************************************
 * copyright (c) 2009 - 2010 Simon Allen
 *
 * This file is part of Convex Media Converter.
 *
 * Convex Media Converter is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Convex Media Converter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Convex Media Converter; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 ******************************************************************************/


#include "constants.h"
#include "MainWindow/mainwindow.h"

#include <iostream>
#include <cstdlib>
#include <new>

#include <QApplication>

using namespace std;


/**
  * Function used to handle out-of-memory errors.
  */
void NewHandler()
{
	cerr << "\nError: Memory could not be allocated.\n";

	exit(1);
}

int main(int argc, char *argv[])
{
	set_new_handler(NewHandler);

	QStringList fileArgs;
	QApplication convex(argc, argv);

	QApplication::setApplicationName("Convex Media Converter");

	MainWindow *mainWindow = new MainWindow;

	if (!mainWindow->initCodecs())
		return 1;

	for (int i = 1; i < argc; i++)
		fileArgs << argv[i];

	if (fileArgs.size() > 0) // Add file arguements to list of input files.
		mainWindow->addInputFiles(fileArgs);

	mainWindow->setGeometry(); // Set window on-screen geometry.
	mainWindow->show();

	return convex.exec(); // Pass control to Qt.
}
